// pages/inpatient-recharge-success/inpatient-recharge-success.js
Page({
  data: {
    rechargeAmount: 0,
    inpatientName: '',
    rechargeTime: '',
    transactionNumber: ''
  },

  onLoad(options) {
    console.log('住院充值成功页面加载', options);
    
    // 获取传递的参数
    if (options.amount && options.inpatientName) {
      const now = new Date();
      const timeString = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')} ${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}:${String(now.getSeconds()).padStart(2, '0')}`;
      
      // 生成交易号
      const transactionNumber = 'IN' + Date.now() + Math.random().toString(36).substr(2, 6).toUpperCase();
      
      this.setData({
        rechargeAmount: parseFloat(options.amount),
        inpatientName: options.inpatientName,
        rechargeTime: timeString,
        transactionNumber: transactionNumber
      });
    }
  },

  // 查看充值记录
  viewRechargeHistory() {
    wx.navigateTo({
      url: '/pages/recharge-history/recharge-history'
    });
  },

  // 返回首页
  goToHome() {
    wx.switchTab({
      url: '/pages/index/index'
    });
  },

  // 继续充值
  continueRecharge() {
    wx.navigateBack({
      delta: 1
    });
  },

  onShow() {
    console.log('住院充值成功页面显示');
  }
});
